home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Personal Computer World 2009 February
/
PCWFEB09.iso
/
Software
/
Resources
/
Chat & Communication
/
Digsby build 37
/
digsby_setup.exe
/
lib
/
oscar
/
ssi
/
SSIItem.pyo
(
.txt
)
< prev
next >
Wrap
Python Compiled Bytecode
|
2008-10-13
|
14KB
|
410 lines
# Source Generated with Decompyle++
# File: in.pyo (Python 2.5)
from __future__ import with_statement
from util.primitives import odict
import traceback
import struct
import oscar
import contacts
from util.observe import list_notify
import warnings
import logging
from oscar.OscarBuddies import OscarBuddy
from traceback import print_stack
import common
from contacts import Contact
log = logging.getLogger('oscar.ssiitem')
class OscarContact(Contact):
_renderer = 'Contact'
inherited_actions = [
OscarBuddy]
def __init__(self, *a, **k):
Contact.__init__(self, *a, **k)
self.ssis = self.protocol.ssimanager.ssis
def get_remote_alias(self):
try:
friendly = self.ssis[self.id].get_alias().decode('fuzzy utf-8')
if self.buddy._friendly_name is None:
self.buddy._friendly_name = friendly
return friendly
except KeyError:
return None
def set_remote_alias(self, newname):
self.protocol.set_remote_alias(self, newname)
remote_alias = property(get_remote_alias, set_remote_alias)
def rename_gui(self):
s = Contact.rename_gui(self)
if s is not None:
self.remote_alias = s
rename_gui = common.action()(rename_gui)
def block(self, *a, **k):
return Contact.block(self, *a, **k)
block = common.action(Contact._block_pred)(block)
def unblock(self, *a, **k):
return Contact.unblock(self, *a, **k)
unblock = common.action(Contact._unblock_pred)(unblock)
class SSIItem(object):
def __init__(self, name, group_id, item_id, type_ = None, tlvs = None, **k):
if not isinstance(name, str):
raise TypeError('SSIItem.name must be str, not %s' % type(name))
type_ = k.pop('type', type_)
if k:
raise Exception('Only one extra keyword argument ("type") is allowed for SSIItems')
self.name = name
self.group_id = group_id
self.item_id = item_id
if not type_:
pass
self.type = 0
if not tlvs:
pass
self.tlvs = odict({ })
self.c8_to_ints()
def set_name(self, name):
if not isinstance(name, str):
raise TypeError('setting SSIItem.name to something that is not str: %s' % type(name))
self._name = name
def get_name(self):
return self._name
name = property(get_name, set_name)
def tlv_tuple(self):
return (self.group_id, self.item_id)
tlv_tuple = property(tlv_tuple)
def to_bytes(self):
tlvs_string = ''
for type, val in self.tlvs.items():
if type != 200:
if hasattr(val, 'value'):
tlvs_string += oscar.util.tlv(val.type, val.length, val.value)
else:
tlvs_string += oscar.util.tlv(type, val)
hasattr(val, 'value')
type += ''.join([], []([ struct.pack('!H', short) for short in val ]))
nlen = len(self.name)
tlen = len(tlvs_string)
return struct.pack('!H%dsHHHH%ds' % (nlen, tlen), nlen, self.name, self.group_id, self.item_id, self.type, tlen, tlvs_string)
def c8_to_ints(self):
if 200 in self.tlvs and isinstance(self.tlvs[200], basestring):
self.tlvs[200] = oscar.unpack((('list', 'list', 'H'),), self.tlvs[200])[0]
def clone(self):
return oscar.unpack((('ssi', 'ssi'),), self.to_bytes())[0]
def add_item_to_group(self, id_to_add, position = 0):
if self.type != 1:
raise AssertionError(repr(self) + ' is not a group')
else:
self.tlvs.setdefault(200, []).insert(position, id_to_add)
def remove_item_from_group(self, id_to_remove):
if self.type != 1:
raise AssertionError(repr(self) + ' is not a group')
try:
self.tlvs.setdefault(200, [
id_to_remove]).remove(id_to_remove)
except ValueError:
pass
if not self.tlvs[200]:
del self.tlvs[200]
def get_item_position(self, id_to_find):
if self.type != 1:
raise AssertionError(repr(self) + ' is not a group')
try:
return self.tlvs.get(200, []).index(id_to_find)
except ValueError:
return None
def move_item_to_position(self, id_to_move, position):
curposition = self.get_item_position(id_to_move)
if curposition is None:
raise AssertionError(repr(self) + ' does not contain %d' % id_to_move)
if position != curposition:
self.remove_item_from_group(id_to_move)
self.add_item_to_group(id_to_move, position)
def get_alias(self):
return self.tlvs.get(305, None)
def set_alias(self, alias):
if alias:
self.tlvs[305] = alias
else:
self.remove_alias()
def remove_alias(self):
self.remove_tlv(305)
alias = property(get_alias, doc = 'this is the alias of the buddy')
def get_comment(self):
return self.tlvs.get(316, None)
def set_comment(self, comment):
if comment:
self.tlvs[316] = comment
else:
self.remove_comment()
def remove_comment(self):
self.remove_tlv(316)
comment = property(get_comment, doc = 'this is the comment about the buddy')
def remove_tlv(self, type):
try:
del self.tlvs[type]
except KeyError:
pass
def __repr__(self):
return '<SSI Item: name: %s, group_id: %d, item_id: %d, type: %d>' % (self.name, self.group_id, self.item_id, self.type)
class OscarSSIs(dict):
def __init__(self, manager):
self.manager = manager
self.root_group = SSIGroup(None, self.manager)
self.groups = {
(0, 0): self.root_group }
return dict.__init__(self)
def __setitem__(self, key, ssi, modify = False):
tupled_key = tuple_key(ssi)
if isinstance(key, SSIItem):
pass
if ssi.type == 1:
self.root_group.frozen().__enter__()
try:
if tupled_key in self.groups:
self.groups[tupled_key].set_ssi(ssi)
else:
self.groups[tupled_key] = SSIGroup(ssi, self.manager)
finally:
pass
elif modify and ssi.type == 0:
if 348 in ssi.tlvs or 349 in ssi.tlvs:
self.manager.o.get_buddy_info(ssi)
return dict.__setitem__(self, tupled_key, ssi)
def get_group(self, key):
return self.groups[tuple_key(key)]
def __getitem__(self, key):
return dict.__getitem__(self, tuple_key(key))
def __contains__(self, key):
return dict.__contains__(self, tuple_key(key))
def __delitem__(self, key):
return dict.__delitem__(self, tuple_key(key))
def update(self, hash, modify = False):
self.root_group.frozen().__enter__()
try:
for k, v in hash.items():
self.__setitem__(k, v, modify = modify)
finally:
pass
def fix_group_c8(self):
groups = _[1]
for g_id, i_id in groups:
known_locs = dict((lambda .0: for x, y in .0:
(y, x))(enumerate(gm_ids)))
locations = { }
for possible in m_ids:
if possible in known_locs:
locations[possible] = known_locs[possible]
continue
inverted = struct.unpack('<H', struct.pack('>H', possible))[0]
if inverted in known_locs:
locations[possible] = known_locs[inverted]
continue
locations[possible] = len(m_ids)
new_gm_ids = sorted(m_ids, key = locations.__getitem__)
self[(g_id, i_id)].tlvs[200] = new_gm_ids
def tuple_key(key):
if isinstance(key, int):
return (key, 0)
if isinstance(key, SSIItem):
return (key.group_id, key.item_id)
if isinstance(key, tuple) and len(key) == 2 and isinstance(key[0], int) and isinstance(key[1], int):
return key
raise AssertionError(repr(key) + ' is not a valid ssi key')
class SSIGroup(contacts.Group):
_renderer = 'Group'
def __init__(self, new_ssi, ssi_manager):
self.my_ssi = new_ssi
self.ssi_manager = ssi_manager
if self.my_ssi is None:
self.my_ssi = SSIItem('root', 0, 0, 1)
groupname = self.my_ssi.name.decode('utf-8', 'replace')
contacts.Group.__init__(self, groupname, ssi_manager.o, self.my_ssi.group_id)
def set_ssi(self, new_ssi):
oldname = self.my_ssi.name
self.my_ssi = new_ssi
self.name = self.my_ssi.name.decode('utf-8', 'replace')
if oldname != self.name:
self.notify('name', oldname, self.name)
def __getitem__(self, index):
g_id = self.my_ssi.group_id
tlv = self.my_ssi.tlvs.get(200, [])
start_index = index
ssi = None
while ssi is None:
try:
i_id = tlv[index]
except IndexError:
break
if g_id:
try:
ssi = self.ssi_manager.ssis[(g_id, i_id)]
except KeyError:
e = None
index += 1
continue
return OscarContact(self.ssi_manager.o.buddies[ssi.name], (g_id, i_id))
continue
return self.ssi_manager.ssis.get_group((i_id, 0))
if ssi is None:
warnings.warn('Error finding SSI %r in group (id=%r)' % (start_index, g_id))
raise IndexError('SSI Item not found in group(id=%r): %r', index, g_id)
def __iter__(self):
for i in xrange(len(self)):
try:
yield self[i]
continue
except (KeyError, IndexError):
continue
continue
def online(self):
return bool(self.num_online)
online = property(online)
def num_online(self):
ss = self.ssi_manager.ssis
bs = self.ssi_manager.o.buddies
total = 0
g_id = self.my_ssi.group_id
tlv = self.my_ssi.tlvs.get(200, [])
return total
num_online = property(num_online)
def find(self, obj):
return list.find(self, obj)
def __len__(self):
return len(self.my_ssi.tlvs.get(200, []))